package com.marion.mzuul.controller;

import com.marion.mzuul.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cache")
public class CacheController {

    @Autowired
    private UserService userService;

    /**
     * guava cache set
     */
    @GetMapping("/name/edit")
    public Object editName(@RequestParam long uid,
                           @RequestParam String name) {
        return userService.editName(uid, name);
    }

    /**
     * no cache get
     */
    @GetMapping("/name/nocache")
    public Object name(@RequestParam long uid) {
        return userService.userNameNoCache(uid);
    }

    /**
     * guava cache get
     */
    @GetMapping("/name/cache")
    public Object nameCache(@RequestParam long uid) {
        return userService.userName(uid);
    }

    /**
     * ehcache get
     */
    @GetMapping("/name/ehcache")
    public Object ehcache(@RequestParam long uid) {
        return userService.ehcache(uid);
    }

    /**
     * redis get
     */
    @GetMapping("/name/redis")
    public Object redis(@RequestParam long uid) {
        return userService.redis(uid);
    }
}
